#lang racket

(define (rand-update x) (remainder (+ (* 839 x) 1877) 3571))

(define random-init 100)

(define rand
  (let ((x random-init))
    (begin
      (define (next-rand)
        (set! x (rand-update x))
        x)
      (define (dispatch y)
        (cond ((eq? y 'generate) (next-rand))
              ((eq? y 'reset) (set! x random-init)
                              x)
              (else "unknown parameter: " y)))
      dispatch)))

(rand 'generate)
(rand 'generate)
(rand 'generate)

(rand 'reset)

(rand 'generate)
(rand 'generate)
(rand 'generate)